import 'dart:async';
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:flutter_app/Utils/Constants.dart';
import 'package:shared_preferences/shared_preferences.dart';

class DioUtils {
  static Dio _dio;

  instance() {
    if (_dio == null) {
      _dio = Dio(Options(connectTimeout: 7000, receiveTimeout: 7000));
    }
    return _dio;
  }

//  post(final RequestCallback callback, final RequestType type,
//      Map<String, String> map) async {
//    SharedPreferences _prefs = await SharedPreferences.getInstance();
//    try {
//      Response response = _instance().post(
//          'http://' + _prefs.getString(Constants.url) + '/job.aspx',
//          data: map) as Response;
//      Map<String, dynamic> resp = json.decode(response.data);
//      if (resp['Status'] == '0')
//        callback.success(resp, type);
//      else
//        callback.fail(resp, type);
//    } catch (e) {
//      print(e);
//      callback.error(e.toString(), type);
//    }
//  }
}

abstract class RequestCallback {
  void success(final Map<String, dynamic> response, final RequestType type);

  void fail(final Map<String, dynamic> response, final RequestType type);

  void error(final String response, final RequestType type);
}
